/*
===========华润通==========
H5登录抓包 ：https://cloud.huaruntong.cn/web/online/?mFrom=fastLogin&mFrom=quickRegister#/signIn?utm_source=hrt&utm_medium=flzx&utm_content=qd0228&utm_campaign=qd0228&inviteCode=2e7cbec65eb14497bae6d29103c000f6
或者华润通APP 域名https://mid.huaruntong.cn/api/user/memberinfo/appBootstarp 返回文本里的token
以上都是抓token
变量
export hrthd='token'
多号@或换行隔开

new Env("华润通")
cron: 0 5 8 * * *
fix 20240625 ArcadiaScriptPublic  频道：https://t.me/ArcadiaScript 群组：https://t.me/ArcadiaScriptPublic
增加打印签到信息
更新cron
*/

const $ = new Env("华润通"),
  axios = require("axios");
var crypto = require("crypto");
const {
    log
  } = console,
  Notify = 1,
  debug = 0;
let hrthd = ($.isNode() ? process.env.hrthd : $.getdata("hrthd")) || "",
  hrthdArr = [],
  hrtpro = hrthdArr[0];
  data = "",
  msg = "";
!(async () => {
  if (typeof $request !== "undefined") {
    await GetRewrite();
  } else {
    if (!(await Envs())) return;else {
      log("\n\n=============================================    \n脚本执行 - 北京时间(UTC+8)：" + new Date(new Date().getTime() + new Date().getTimezoneOffset() * 60 * 1000 + 8 * 60 * 60 * 1000).toLocaleString() + " \n=============================================\n");
      log("\n=================== 共找到 " + hrthdArr.length + " 个账号 ===================");
      debug && log("【debug】 这是你的全部账号数组:\n " + hrthdArr);
      for (let _0x3bf82c = 0; _0x3bf82c < hrthdArr.length; _0x3bf82c++) {
        let _0x3b9a84 = _0x3bf82c + 1;
        addNotifyStr("\n==== 开始华润通【第 " + _0x3b9a84 + " 个账号】====", true);
        hrthd = hrthdArr[_0x3bf82c];
        await questionget();
        await getInvitationCode();
        await saveQuestionSignin(nos);
        await queryInvitedToDraw();
      }
    }
  }
})().catch(_0x145d21 => log(_0x145d21)).finally(() => $.done());
async function questionget() {
  return new Promise(_0x5950c0 => {
    uudi = create_guid();
    var _0x1eb360 = {
        "auth": (n = "API_AUTH_H5", a = new Date().getTime(), s = uudi, c = [n, "1c6120fd-5ad3-4c2d-8cb7-b87a707f416d", a, s].sort().join(""), {
          "appid": n,
          "nonce": s,
          "timestamp": a,
          "signature": md5(c)
        }),
        "num": 1
      },
      _0x37af86 = {
        "method": "POST",
        "url": "https://mid.huaruntong.cn/api/question/get",
        "headers": {
          "Content-Type": "application/json;charset=UTF-8",
          "Host": "mid.huaruntong.cn",
          "Origin": "https://cloud.huaruntong.cn",
          "Referer": "https://cloud.huaruntong.cn/",
          "sec-ch-ua": "\"\"",
          "sec-ch-ua-mobile": "?1",
          "sec-ch-ua-platform": "\"\"",
          "Sec-Fetch-Dest": "empty",
          "Sec-Fetch-Mode": "cors",
          "Sec-Fetch-Site": "same-site",
          "User-Agent": "Mozilla/5.0 (Linux; Android 10; PCAM00 Build/QKQ1.190918.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.92 Mobile Safari/537.36/ hrtbrowser/5.3.5 grayscale/0",
          "x-Hrt-Mid-Appid": "API_AUTH_WEB"
        },
        "data": _0x1eb360
      };
    debug && (log("\n【debug】=============== 这是  请求 url ==============="), log(JSON.stringify(_0x37af86)));
    axios.request(_0x37af86).then(async function (_0x1c53b4) {
      try {
        data = _0x1c53b4.data;
        debug && (log("\n\n【debug】===============这是 返回data=============="), log(JSON.stringify(_0x1c53b4.data)));
        if (data.code == "S0A00000") {
          log(data.msg);
          ansid = data.data[0].id;
          nos = data.data[0].no;
          answers = data.data[0].keywords;
          console.log(ansid, nos, answers);
          await questioncount(ansid);
        } else log(data.msg);
      } catch (_0x48bd73) {
        log("异常：" + data + "，原因：" + data.message);
      }
    }).catch(function (_0x527aae) {
      console.error(_0x527aae);
    }).then(_0x2618bb => {
      _0x5950c0();
    });
  });
}
async function questioncount(_0x212c42) {
  return new Promise(_0x3da464 => {
    var _0x391d96 = {
        "auth": (n = "API_AUTH_H5", a = new Date().getTime(), s = uudi, c = [n, "1c6120fd-5ad3-4c2d-8cb7-b87a707f416d", a, s].sort().join(""), {
          "appid": n,
          "nonce": s,
          "timestamp": a,
          "signature": md5(c)
        }),
        "id": _0x212c42,
        "status": 1
      },
      _0x2b8824 = {
        "method": "POST",
        "url": "https://mid.huaruntong.cn/api/question/count",
        "headers": {
          "Content-Type": "application/json;charset=UTF-8",
          "Host": "mid.huaruntong.cn",
          "Origin": "https://cloud.huaruntong.cn",
          "Referer": "https://cloud.huaruntong.cn/",
          "sec-ch-ua": "\"\"",
          "sec-ch-ua-mobile": "?1",
          "sec-ch-ua-platform": "\"\"",
          "Sec-Fetch-Dest": "empty",
          "Sec-Fetch-Mode": "cors",
          "Sec-Fetch-Site": "same-site",
          "User-Agent": "Mozilla/5.0 (Linux; Android 10; PCAM00 Build/QKQ1.190918.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.92 Mobile Safari/537.36/ hrtbrowser/5.3.5 grayscale/0",
          "x-Hrt-Mid-Appid": "API_AUTH_WEB"
        },
        "data": _0x391d96
      };
    if (debug) {
      log("\n【debug】=============== 这是  请求 url ===============");
      log(JSON.stringify(_0x2b8824));
    }
    axios.request(_0x2b8824).then(async function (_0x502df4) {
      try {
        data = _0x502df4.data;
        debug && (log("\n\n【debug】===============这是 返回data=============="), log(JSON.stringify(_0x502df4.data)));
        if (data.code == "S0A00000") log(data.msg);else log(data.msg);
      } catch (_0x32761e) {
        log("异常：" + data + "，原因：" + data.message);
      }
    }).catch(function (_0x54761b) {
      console.error(_0x54761b);
    }).then(_0x19ca25 => {
      _0x3da464();
    });
  });
}
async function saveQuestionSignin(_0x26da4f) {
  return new Promise(_0x2c4aab => {
    body = {
      "answerResult": 1,
      "questionId": _0x26da4f,
      "channelId": "APP",
      "merchantCode": "1641000001532",
      "storeCode": "qiandaosonjifen",
      "sysId": "T0000001",
      "transactionUuid": uudi,
      "inviteCode": ints,
      "token": hrthd,
      "apiPath": "%2Fapi%2Fpoints%2FsaveQuestionSignin",
      "appId": "API_AUTH_WEB",
      "timestamp": new Date().getTime()
    };
    var _0x43a246 = {
      "method": "POST",
      "url": "https://mid.huaruntong.cn/api/points/saveQuestionSignin",
      "headers": {
        "Content-Type": "application/json;charset=UTF-8",
        "Host": "mid.huaruntong.cn",
        "Origin": "https://cloud.huaruntong.cn",
        "Referer": "https://cloud.huaruntong.cn/",
        "sec-ch-ua": "\"\"",
        "sec-ch-ua-mobile": "?1",
        "sec-ch-ua-platform": "\"\"",
        "Sec-Fetch-Dest": "empty",
        "Sec-Fetch-Mode": "cors",
        "Sec-Fetch-Site": "same-site",
        "User-Agent": "Mozilla/5.0 (Linux; Android 10; PCAM00 Build/QKQ1.190918.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.92 Mobile Safari/537.36/ hrtbrowser/5.3.5 grayscale/0",
        "x-Hrt-Mid-Appid": "API_AUTH_WEB"
      },
      "data": signs(body)
    };
    debug && (log("\n【debug】=============== 这是  请求 url ==============="), log(JSON.stringify(_0x43a246)));
    axios.request(_0x43a246).then(async function (_0x47b2ec) {
      try {
        data = _0x47b2ec.data;
        if (debug) {
          log("\n\n【debug】===============这是 返回data==============");
          log(JSON.stringify(_0x47b2ec.data));
        }
        if (data.code == "S0A00000") {
          if (Object.keys(data.data).length > 0) log("签到获得：" + data.data.point), msg += "\n签到获得：" + data.data.point;else log(data.msg);
          msg += "\n" + data.msg;
        } else log(data.msg);
        msg += "\n" + data.msg;
      } catch (_0x50c0fb) {
        log("异常：" + data + "，原因：" + data.message);
      }
    }).catch(function (_0x4d5369) {
      console.error(_0x4d5369);
    }).then(_0x52b92e => {
      _0x2c4aab();
    });
  });
}
async function drawInvitePoint() {
  return new Promise(_0x4c5aa7 => {
    body = {
      "apiPath": "%2Fapi%2Fpoints%2FdrawInvitePoint",
      "timestamp": new Date().getTime(),
      "appId": "API_AUTH_WEB",
      "token": hrthd
    };
    var _0x28c1e8 = {
      "method": "POST",
      "url": "https://mid.huaruntong.cn/api/points/drawInvitePoint",
      "headers": {
        "Content-Type": "application/json;charset=UTF-8",
        "Host": "mid.huaruntong.cn",
        "Origin": "https://cloud.huaruntong.cn",
        "Referer": "https://cloud.huaruntong.cn/",
        "sec-ch-ua": "\"\"",
        "sec-ch-ua-mobile": "?1",
        "sec-ch-ua-platform": "\"\"",
        "Sec-Fetch-Dest": "empty",
        "Sec-Fetch-Mode": "cors",
        "Sec-Fetch-Site": "same-site",
        "User-Agent": "Mozilla/5.0 (Linux; Android 10; PCAM00 Build/QKQ1.190918.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.92 Mobile Safari/537.36/ hrtbrowser/5.3.5 grayscale/0",
        "x-Hrt-Mid-Appid": "API_AUTH_WEB"
      },
      "data": signs(body)
    };
    debug && (log("\n【debug】=============== 这是  请求 url ==============="), log(JSON.stringify(_0x28c1e8)));
    axios.request(_0x28c1e8).then(async function (_0x1f816c) {
      try {
        data = _0x1f816c.data;
        if (debug) {
          log("\n\n【debug】===============这是 返回data==============");
          log(JSON.stringify(_0x1f816c.data));
        }
        log(JSON.stringify(_0x1f816c.data));
        if (data.code == "S0A00000") log(data);else log(data);
      } catch (_0x95511d) {
        log("异常：" + data + "，原因：" + data.message);
      }
    }).catch(function (_0x2ecf25) {
      console.error(_0x2ecf25);
    }).then(_0x16689b => {
      _0x4c5aa7();
    });
  });
}
async function queryInvitedToDraw() {
  return new Promise(_0x1f1530 => {
    body = {
      "apiPath": "%2Fapi%2Fpoints%2FqueryInvitedToDraw",
      "timestamp": new Date().getTime(),
      "appId": "API_AUTH_WEB",
      "token": hrthd
    };
    var _0x5657dc = {
      "method": "POST",
      "url": "https://mid.huaruntong.cn/api/points/queryInvitedToDraw",
      "headers": {
        "Content-Type": "application/json;charset=UTF-8",
        "Host": "mid.huaruntong.cn",
        "Origin": "https://cloud.huaruntong.cn",
        "Referer": "https://cloud.huaruntong.cn/",
        "sec-ch-ua": "\"\"",
        "sec-ch-ua-mobile": "?1",
        "sec-ch-ua-platform": "\"\"",
        "Sec-Fetch-Dest": "empty",
        "Sec-Fetch-Mode": "cors",
        "Sec-Fetch-Site": "same-site",
        "User-Agent": "Mozilla/5.0 (Linux; Android 10; PCAM00 Build/QKQ1.190918.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.92 Mobile Safari/537.36/ hrtbrowser/5.3.5 grayscale/0",
        "x-Hrt-Mid-Appid": "API_AUTH_WEB"
      },
      "data": signs(body)
    };
    debug && (log("\n【debug】=============== 这是  请求 url ==============="), log(JSON.stringify(_0x5657dc)));
    axios.request(_0x5657dc).then(async function (_0x371249) {
      try {
        data = _0x371249.data;
        debug && (log("\n\n【debug】===============这是 返回data=============="), log(JSON.stringify(_0x371249.data)));
        if (data.code == "S0A00000") Object.keys(data.data).length > 0 && (await drawInvitePoint());else log(data);
      } catch (_0x8c3dc2) {
        log("异常：" + data + "，原因：" + data.message);
      }
    }).catch(function (_0x2fc9a6) {
      console.error(_0x2fc9a6);
    }).then(_0x5ef956 => {
      _0x1f1530();
    });
  });
}
async function getInvitationCode() {
  return new Promise(_0x47c7ab => {
    body = {
      "apiPath": "%2Fapi%2Fpoints%2FgetInvitationCode",
      "timestamp": new Date().getTime(),
      "appId": "API_AUTH_WEB",
      "token": hrtpro
    };
    var _0x2fa3db = {
      "method": "POST",
      "url": "https://mid.huaruntong.cn/api/points/getInvitationCode",
      "headers": {
        "Content-Type": "application/json;charset=UTF-8",
        "Host": "mid.huaruntong.cn",
        "Origin": "https://cloud.huaruntong.cn",
        "Referer": "https://cloud.huaruntong.cn/",
        "sec-ch-ua": "\"\"",
        "sec-ch-ua-mobile": "?1",
        "sec-ch-ua-platform": "\"\"",
        "Sec-Fetch-Dest": "empty",
        "Sec-Fetch-Mode": "cors",
        "Sec-Fetch-Site": "same-site",
        "User-Agent": "Mozilla/5.0 (Linux; Android 10; PCAM00 Build/QKQ1.190918.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.92 Mobile Safari/537.36/ hrtbrowser/5.3.5 grayscale/0",
        "x-Hrt-Mid-Appid": "API_AUTH_WEB"
      },
      "data": signs(body)
    };
    if (debug) {
      log("\n【debug】=============== 这是  请求 url ===============");
      log(JSON.stringify(_0x2fa3db));
    }
    axios.request(_0x2fa3db).then(async function (_0x566413) {
      try {
        data = _0x566413.data;
        debug && (log("\n\n【debug】===============这是 返回data=============="), log(JSON.stringify(_0x566413.data)));
        if (data.code == "S0A00000") ints = data.data.data.invitationCode;else log(data.msg);
      } catch (_0x39ff73) {
        log("异常：" + data + "，原因：" + data.message);
      }
    }).catch(function (_0x55226d) {
      console.error(_0x55226d);
    }).then(_0x234725 => {
      _0x47c7ab();
    });
  });
}
function create_guid() {
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (_0xc39288) {
    var _0x969a6e = 16 * Math.random() | 0;
    return ("x" == _0xc39288 ? _0x969a6e : _0x969a6e & 3 | 8).toString(16);
  });
}
function encrypt(_0x37634b, _0x2b281d, _0x3c9d45) {
  const _0x501f52 = crypto.createCipheriv("aes-128-cbc", _0x2b281d, _0x3c9d45);
  let _0x333a85 = _0x501f52.update(_0x37634b);
  return _0x333a85 = Buffer.concat([_0x333a85, _0x501f52.final()]), _0x333a85.toString("base64");
}
function rsa(_0x568c7a) {
  const _0x122c4d = crypto.publicEncrypt({
    "key": "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDuAiqDmvn9Rf15o21qkDxN0rUf\nZsX6rVBrtfgY6tamN2Yn+1D3eHZJuKNlucyqeBr6nmfN2srYAX+oyCXr5vWwFclj\nPuWh8aSASqyk7MfbAv5Q4VqYS7lsYUQRdw4plZG0NASDeBvHWi3lsHjGfNb7iUvg\nrk312EDfBHtRgDvB0QIDAQAB\n-----END PUBLIC KEY-----",
    "padding": crypto.constants.RSA_PKCS1_OAEP_PADDING
  }, Buffer.from(_0x568c7a));
  return _0x122c4d.toString("base64");
}
function signs(_0x4a9409) {
  eee = {
    "secret": "c274fc67-19f9-47ba-bb84-585a2e3a1f6a",
    "pubKey": "-----BEGIN PUBLIC KEY-----MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDuAiqDmvn9Rf15o21qkDxN0rUfZsX6rVBrtfgY6tamN2Yn+1D3eHZJuKNlucyqeBr6nmfN2srYAX+oyCXr5vWwFcljPuWh8aSASqyk7MfbAv5Q4VqYS7lsYUQRdw4plZG0NASDeBvHWi3lsHjGfNb7iUvgrk312EDfBHtRgDvB0QIDAQAB-----END PUBLIC KEY-----"
  };
  var _0x4a9409 = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
  if (_0x4a9409.apiPath) {
    _0x4a9409.appId = _0x4a9409.appId;
    _0x4a9409.timestamp = _0x4a9409.timestamp || Date.now();
    var _0x5d3a18 = [];
    for (var _0x3001af in _0x4a9409) {
      var _0x1c7d3a = _0x4a9409[_0x3001af];
      void 0 !== _0x1c7d3a && (_0x1c7d3a instanceof Date ? _0x1c7d3a = JSON.stringify(_0x1c7d3a).replace(/"/g, "") : "object" === (void 0 === _0x1c7d3a ? "undefined" : "number") && (_0x1c7d3a = JSON.stringify(_0x1c7d3a)), _0x5d3a18.push(_0x3001af + "=" + _0x1c7d3a));
    }
    const _0x134aee = crypto.createHmac("md5", eee.secret);
    _0x134aee.update(encodeUtf8(_0x5d3a18.sort().join("&")));
    const _0x2354e5 = _0x134aee.digest("hex");
    _0x4a9409.signature = _0x2354e5;
    var _0x3b9681 = i(),
      _0x18f51f = encrypt(JSON.stringify(_0x4a9409), Buffer.alloc(16, _0x3b9681), Buffer.alloc(16, ""));
    return {
      "key": rsa(_0x3b9681),
      "data": _0x18f51f
    };
  }
}
function i() {
  for (var _0x35bb73 = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"], _0x127c5b = _0x35bb73.length, _0x4a63a7 = "", _0x31a9a6 = 0; _0x31a9a6 < 16; _0x31a9a6++) _0x4a63a7 += _0x35bb73[Math.floor(Math.random() * _0x127c5b)];
  return _0x4a63a7;
}
encodeUtf8 = function (_0x2aa9f8) {
  return unescape(encodeURIComponent(_0x2aa9f8));
};
function md5(_0x332e57) {
  const _0x107efb = crypto.createHash("md5");
  _0x107efb.update(_0x332e57);
  const _0x3e9343 = _0x107efb.digest("hex");
  return _0x3e9343;
}

async function Envs() {
  if (hrthd) {
    if (hrthd.indexOf("@") != -1) hrthd.split("@").forEach(_0x26d35f => {
      hrthdArr.push(_0x26d35f);
    });else {
      if (hrthd.indexOf("\n") != -1) {
        hrthd.split("\n").forEach(_0x5a86ef => {
          hrthdArr.push(_0x5a86ef);
        });
      } else hrthdArr.push(hrthd);
    }
  } else {
    log("\n 【" + $.name + "】：未填写变量 hrthd");
    return;
  }
  hrtpro = hrthdArr[0];
  log("邀请账号：" + hrtpro)
  return true;
}
function addNotifyStr(_0x5cd1ed, _0x15de1d = true) {
  _0x15de1d && log(_0x5cd1ed);
  msg += _0x5cd1ed;
}
async function SendMsg(_0x514f9b) {
  if (!_0x514f9b) return;
  if (Notify > 0) {
    if ($.isNode()) {
      var _0x1e0209 = require("./sendNotify");
      await _0x1e0209.sendNotify($.name, _0x514f9b);
    } else {
      $.msg(_0x514f9b);
    }
  } else {
    log(_0x514f9b);
  }
}
function Env(t, e) {
  "undefined" != typeof process && JSON.stringify(process.env).indexOf("GITHUB") > -1 && process.exit(0);
  class s {
    constructor(t) {
      this.env = t;
    }
    send(t, e = "GET") {
      t = "string" == typeof t ? {
        url: t
      } : t;
      let s = this.get;
      return "POST" === e && (s = this.post), new Promise((e, i) => {
        s.call(this, t, (t, s, r) => {
          t ? i(t) : e(s);
        });
      });
    }
    get(t) {
      return this.send.call(this.env, t);
    }
    post(t) {
      return this.send.call(this.env, t, "POST");
    }
  }
  return new class {
    constructor(t, e) {
      this.name = t;
      this.http = new s(this);
      this.data = null;
      this.dataFile = "box.dat";
      this.logs = [];
      this.isMute = !1;
      this.isNeedRewrite = !1;
      this.logSeparator = "\n";
      this.startTime = new Date().getTime();
      Object.assign(this, e);
      this.log("", `🔔${this.name}, 开始!`);
    }
    isNode() {
      return "undefined" != typeof module && !!module.exports;
    }
    isQuanX() {
      return "undefined" != typeof $task;
    }
    isSurge() {
      return "undefined" != typeof $httpClient && "undefined" == typeof $loon;
    }
    isLoon() {
      return "undefined" != typeof $loon;
    }
    toObj(t, e = null) {
      try {
        return JSON.parse(t);
      } catch {
        return e;
      }
    }
    toStr(t, e = null) {
      try {
        return JSON.stringify(t);
      } catch {
        return e;
      }
    }
    getjson(t, e) {
      let s = e;
      const i = this.getdata(t);
      if (i) try {
        s = JSON.parse(this.getdata(t));
      } catch {}
      return s;
    }
    setjson(t, e) {
      try {
        return this.setdata(JSON.stringify(t), e);
      } catch {
        return !1;
      }
    }
    getScript(t) {
      return new Promise(e => {
        this.get({
          url: t
        }, (t, s, i) => e(i));
      });
    }
    runScript(t, e) {
      return new Promise(s => {
        let i = this.getdata("@chavy_boxjs_userCfgs.httpapi");
        i = i ? i.replace(/\n/g, "").trim() : i;
        let r = this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");
        r = r ? 1 * r : 20;
        r = e && e.timeout ? e.timeout : r;
        const [o, h] = i.split("@"),
          n = {
            url: `http://${h}/v1/scripting/evaluate`,
            body: {
              script_text: t,
              mock_type: "cron",
              timeout: r
            },
            headers: {
              "X-Key": o,
              Accept: "*/*"
            }
          };
        this.post(n, (t, e, i) => s(i));
      }).catch(t => this.logErr(t));
    }
    loaddata() {
      if (!this.isNode()) return {};
      {
        this.fs = this.fs ? this.fs : require("fs");
        this.path = this.path ? this.path : require("path");
        const t = this.path.resolve(this.dataFile),
          e = this.path.resolve(process.cwd(), this.dataFile),
          s = this.fs.existsSync(t),
          i = !s && this.fs.existsSync(e);
        if (!s && !i) return {};
        {
          const i = s ? t : e;
          try {
            return JSON.parse(this.fs.readFileSync(i));
          } catch (t) {
            return {};
          }
        }
      }
    }
    writedata() {
      if (this.isNode()) {
        this.fs = this.fs ? this.fs : require("fs");
        this.path = this.path ? this.path : require("path");
        const t = this.path.resolve(this.dataFile),
          e = this.path.resolve(process.cwd(), this.dataFile),
          s = this.fs.existsSync(t),
          i = !s && this.fs.existsSync(e),
          r = JSON.stringify(this.data);
        s ? this.fs.writeFileSync(t, r) : i ? this.fs.writeFileSync(e, r) : this.fs.writeFileSync(t, r);
      }
    }
    lodash_get(t, e, s) {
      const i = e.replace(/\[(\d+)\]/g, ".$1").split(".");
      let r = t;
      for (const t of i) if (r = Object(r)[t], void 0 === r) return s;
      return r;
    }
    lodash_set(t, e, s) {
      return Object(t) !== t ? t : (Array.isArray(e) || (e = e.toString().match(/[^.[\]]+/g) || []), e.slice(0, -1).reduce((t, s, i) => Object(t[s]) === t[s] ? t[s] : t[s] = Math.abs(e[i + 1]) >> 0 == +e[i + 1] ? [] : {}, t)[e[e.length - 1]] = s, t);
    }
    getdata(t) {
      let e = this.getval(t);
      if (/^@/.test(t)) {
        const [, s, i] = /^@(.*?)\.(.*?)$/.exec(t),
          r = s ? this.getval(s) : "";
        if (r) try {
          const t = JSON.parse(r);
          e = t ? this.lodash_get(t, i, "") : e;
        } catch (t) {
          e = "";
        }
      }
      return e;
    }
    setdata(t, e) {
      let s = false;
      if (/^@/.test(e)) {
        const [, i, r] = /^@(.*?)\.(.*?)$/.exec(e),
          o = this.getval(i),
          h = i ? "null" === o ? null : o || "{}" : "{}";
        try {
          const e = JSON.parse(h);
          this.lodash_set(e, r, t);
          s = this.setval(JSON.stringify(e), i);
        } catch (e) {
          const o = {};
          this.lodash_set(o, r, t);
          s = this.setval(JSON.stringify(o), i);
        }
      } else s = this.setval(t, e);
      return s;
    }
    getval(t) {
      return this.isSurge() || this.isLoon() ? $persistentStore.read(t) : this.isQuanX() ? $prefs.valueForKey(t) : this.isNode() ? (this.data = this.loaddata(), this.data[t]) : this.data && this.data[t] || null;
    }
    setval(t, e) {
      return this.isSurge() || this.isLoon() ? $persistentStore.write(t, e) : this.isQuanX() ? $prefs.setValueForKey(t, e) : this.isNode() ? (this.data = this.loaddata(), this.data[e] = t, this.writedata(), !0) : this.data && this.data[e] || null;
    }
    initGotEnv(t) {
      this.got = this.got ? this.got : require("got");
      this.cktough = this.cktough ? this.cktough : require("tough-cookie");
      this.ckjar = this.ckjar ? this.ckjar : new this.cktough.CookieJar();
      t && (t.headers = t.headers ? t.headers : {}, void 0 === t.headers.Cookie && void 0 === t.cookieJar && (t.cookieJar = this.ckjar));
    }
    get(t, e = () => {}) {
      t.headers && (delete t.headers["Content-Type"], delete t.headers["Content-Length"]);
      this.isSurge() || this.isLoon() ? (this.isSurge() && this.isNeedRewrite && (t.headers = t.headers || {}, Object.assign(t.headers, {
        "X-Surge-Skip-Scripting": !1
      })), $httpClient.get(t, (t, s, i) => {
        !t && s && (s.body = i, s.statusCode = s.status);
        e(t, s, i);
      })) : this.isQuanX() ? (this.isNeedRewrite && (t.opts = t.opts || {}, Object.assign(t.opts, {
        hints: !1
      })), $task.fetch(t).then(t => {
        const {
          statusCode: s,
          statusCode: i,
          headers: r,
          body: o
        } = t;
        e(null, {
          status: s,
          statusCode: i,
          headers: r,
          body: o
        }, o);
      }, t => e(t))) : this.isNode() && (this.initGotEnv(t), this.got(t).on("redirect", (t, e) => {
        try {
          if (t.headers["set-cookie"]) {
            const s = t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();
            s && this.ckjar.setCookieSync(s, null);
            e.cookieJar = this.ckjar;
          }
        } catch (t) {
          this.logErr(t);
        }
      }).then(t => {
        const {
          statusCode: s,
          statusCode: i,
          headers: r,
          body: o
        } = t;
        e(null, {
          status: s,
          statusCode: i,
          headers: r,
          body: o
        }, o);
      }, t => {
        const {
          message: s,
          response: i
        } = t;
        e(s, i, i && i.body);
      }));
    }
    post(t, e = () => {}) {
      if (t.body && t.headers && !t.headers["Content-Type"] && (t.headers["Content-Type"] = "application/x-www-form-urlencoded"), t.headers && delete t.headers["Content-Length"], this.isSurge() || this.isLoon()) this.isSurge() && this.isNeedRewrite && (t.headers = t.headers || {}, Object.assign(t.headers, {
        "X-Surge-Skip-Scripting": !1
      })), $httpClient.post(t, (t, s, i) => {
        !t && s && (s.body = i, s.statusCode = s.status);
        e(t, s, i);
      });else if (this.isQuanX()) t.method = "POST", this.isNeedRewrite && (t.opts = t.opts || {}, Object.assign(t.opts, {
        hints: !1
      })), $task.fetch(t).then(t => {
        const {
          statusCode: s,
          statusCode: i,
          headers: r,
          body: o
        } = t;
        e(null, {
          status: s,
          statusCode: i,
          headers: r,
          body: o
        }, o);
      }, t => e(t));else if (this.isNode()) {
        this.initGotEnv(t);
        const {
          url: s,
          ...i
        } = t;
        this.got.post(s, i).then(t => {
          const {
            statusCode: s,
            statusCode: i,
            headers: r,
            body: o
          } = t;
          e(null, {
            status: s,
            statusCode: i,
            headers: r,
            body: o
          }, o);
        }, t => {
          const {
            message: s,
            response: i
          } = t;
          e(s, i, i && i.body);
        });
      }
    }
    time(t, e = null) {
      const s = e ? new Date(e) : new Date();
      let i = {
        "M+": s.getMonth() + 1,
        "d+": s.getDate(),
        "H+": s.getHours(),
        "m+": s.getMinutes(),
        "s+": s.getSeconds(),
        "q+": Math.floor((s.getMonth() + 3) / 3),
        S: s.getMilliseconds()
      };
      /(y+)/.test(t) && (t = t.replace(RegExp.$1, (s.getFullYear() + "").substr(4 - RegExp.$1.length)));
      for (let e in i) new RegExp("(" + e + ")").test(t) && (t = t.replace(RegExp.$1, 1 == RegExp.$1.length ? i[e] : ("00" + i[e]).substr(("" + i[e]).length)));
      return t;
    }
    msg(e = t, s = "", i = "", r) {
      const o = t => {
        if (!t) return t;
        if ("string" == typeof t) return this.isLoon() ? t : this.isQuanX() ? {
          "open-url": t
        } : this.isSurge() ? {
          url: t
        } : void 0;
        if ("object" == typeof t) {
          if (this.isLoon()) {
            let e = t.openUrl || t.url || t["open-url"],
              s = t.mediaUrl || t["media-url"];
            return {
              openUrl: e,
              mediaUrl: s
            };
          }
          if (this.isQuanX()) {
            let e = t["open-url"] || t.url || t.openUrl,
              s = t["media-url"] || t.mediaUrl;
            return {
              "open-url": e,
              "media-url": s
            };
          }
          if (this.isSurge()) {
            let e = t.url || t.openUrl || t["open-url"];
            return {
              url: e
            };
          }
        }
      };
      if (this.isMute || (this.isSurge() || this.isLoon() ? $notification.post(e, s, i, o(r)) : this.isQuanX() && $notify(e, s, i, o(r))), !this.isMuteLog) {
        let t = ["", "==============📣系统通知📣=============="];
        t.push(e);
        s && t.push(s);
        i && t.push(i);
        console.log(t.join("\n"));
        this.logs = this.logs.concat(t);
      }
    }
    log(...t) {
      t.length > 0 && (this.logs = [...this.logs, ...t]);
      console.log(t.join(this.logSeparator));
    }
    logErr(t, e) {
      const s = !this.isSurge() && !this.isQuanX() && !this.isLoon();
      s ? this.log("", `❗️${this.name}, 错误!`, t.stack) : this.log("", `❗️${this.name}, 错误!`, t);
    }
    wait(t) {
      return new Promise(e => setTimeout(e, t));
    }
    done(t = {}) {
      const e = new Date().getTime(),
        s = (e - this.startTime) / 1000;
      SendMsg(msg);
      this.log("", `🔔${this.name}, 结束! 🕛 ${s} 秒`);
      this.log();
      (this.isSurge() || this.isQuanX() || this.isLoon()) && $done(t);
    }
  }(t, e);
}
